home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
stuffky.exe
/
STUFFKB3.ASM
< prev
Wrap
Assembly Source File
|
1991-07-17
|
25KB
|
572 lines
COMMENT |
STUFFKB3.ASM By Richard Kanarek- Compuserve ID 72371,111
GENIE Address: R.KANAREK
Overview:
+Description of file.
+Notes on the Keyboard Buffer.
+Sample Assembly Language program which stuffs the phrase
"BUY BONDS" into your keyboard buffer. May be easily adapted
for use with Turbo C (tm- Borland Int. Inc.) by changing
a few lines (all of which are marked).
+Sample Turbo C program which calls the assembler routine
and uses it to stuff "RLK" into the buffer.
+Description of file.
---------------------
This file contains information on the operation of the keyboard
buffer in IBM & Zenith personal computers as well as sample procedure
(in Assembler) that can be called from a Turbo C (tm) program. This
file was intended to be compiled using TASM but since only TASM's
MASM mode is used, compilation using Microsoft's (tm) assembler
should not be difficult.
Unlike most programs, whose purpose is only to be executed, the
purpose of this program is to explain the operation of the Keyboard
buffer. This file is meant to help those who might wish to "stuff"
or otherwise modify the keyboard buffer on any IBM computer. Some
reasons why you might want to fiddle with the keyboard buffer:
- Call another program while exiting an already running program
without tying up ANY memory or interfering with the running program
in any way.
- Change the keyboard buffer size to allow more or fewer keystrokes
to be stored.
- Write a TSR that can demonstrate other programs by simulating keystrokes,
without having or needing access to the other programs source code.
Things to consider:
- EXTENSIVELY TEST ANY PROGRAM THAT STUFFS THE KEYBOARD BUFFER!!! Very slight
mistakes can create impressively buggy software! Make sure that the routines
do not leave any lasting effects (i.e. try running other programs after
running any program that stuffs the buffer). Assume that any software
that will stuff the keyboard will crash on your first effort writing it-
IN HEAVEN'S NAME SAVE TO FLOPPY DISK (THEN REMOVE THE DISK FROM YOUR DRIVE)
YOUR WORK IN PROGRESS BEFORE TRYING YOU NEW PROGRAM! HARD DISK USERS- DEBUG
AT YOUR OWN RISK! The memory area near the key board buffer is used for
important purposes by your computer. Accidentally writing to them will cause
the computer to operate unreliably- though not necessarily so unreliably
that you will notice it immediately! For example: while developing the
routines below, there was a bug present which would cause the procedure
to (apparently) not write to the buffer but it did not seem to cause any
other problems (TASM, TLINK, & Turbo C still worked fine). When I tried
starting Turbo Debugger, my computer would lock up! Once again: Test, Test,
Test!!!
- These routines have only been tried on Heath/Zenith XT similar
computer (not 100% clone, but close). Verify on you own if the
concepts described below will work else where!
- If you are sure that your computers BIOS supports int 16h fun 05h you can
use it to safely write data to the keyboard buffer:
Calling Registers: (From "System BIOS for IBM PC/XT/AT Computers &
ax=05h Compatibles", Phoenix Tech. Reference)
ch=scan code
cl=ascii character
Return Registers:
al= 00h=No Error, 01h= Buffer Full.
This BIOS int. is only supported on latter xt and on at computers. To
determine if the computer running a program supports INT 16h fun.'s 5h,10h,
12h...
(quoting Phoenix book...)
a) Use Fun. 05h to write FFFFh to the keyboard buffer. If AL returns 00h
then fun. 05h is supported.
b) Read the keyboard using fun. 10 as many times as there are words in
the keyboard buffer (the book recommends 15). If FFFFh is returned fun.
10h-12h are supported.
- This program was NOT extensively tested. USE AT YOUR OWN RISK! Please
report any problems or useful information on keyboard stuffing to the
author so that I may keep these notes as complete as possible.
- Note: IBM AT & PS/2 Keyboards generate different codes than do the XT
keyboards this program was written for. I don't believe that these
differences will affect this program in any way but this has not been
tested yet. You may wish to check that different keyboards work equally
well before using these routines in any important programs.
- Note: This program was compiled (using Turbo Assembler & TLINK) with
case sensitivity & all debugging options on. Recompiling should not produce
any error messages.
- IMPORTANT: Needless to say (but that won't stop me!)...
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+The information and routines below may be used without charge so long as +
+the author is not held, in any way, labial for the soundness of the routines+
+or accuracy of the information. Any source code included in this file may +
+be considered "Public Domain". RLK Jan 9 1990 +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Notes on the Keyboard Buffer.
------------------------------
The keyboard buffer is a circular buffer.
The main components of the keyboard buffer are:
1) A variable which keeps track of where the scan code for the oldest (first)
unread key is located. This variable is often called the Head.
2) A variable which keeps track of where the scan code for the most recently
press key is located. This variable is often called the Tail.
3) A variable which contains the offset for the beginning of the keyboard
buffer's memory area. This variable is often called the Start.
4) A variable which contains the offset for the end of the keyboard
buffer's memory area. This variable is often called the End.
As keys are pressed, the scan code (WORD) is placed in a memory location
pointed to by Tail. The tail pointer is then incremented by two (2 bytes=
one word) unless the Tail pointer is 2 memory locations (bytes) before
the Head pointer in which case the keyboard buffer is now full.
If incrementing the Tail pointer makes it greater than the value of End,
Tail is set to equal Start.
When a BIOS interrupt reads a scan code from the keyboard buffer, it reads
the scan code pointed to by Head & then increments the Head pointer by
two. (Note: No key is read from the buffer if the buffer is empty, i.e.
if Head=Tail.)
If incrementing the Head pointer makes it greater than the value of End,
Head is set to equal Start.
==IBM========================================================================
(Heath/ZDS computer programmers, see next section).
Note Worthy BIOS/RAM Locations concerning the Keyboard Buffer:
Note Segment = 040h
Offset Data type Description
80h Word Address of the start of the keyboard buffer, i.e.
40h:[40h:80h] = the location of the first word of
the keyboard buffer.
82h Word Address of the end of the keyboard buffer.
1Eh-2Eh -------- 16 bytes of the default keyboard buffer area.
Note: By changing the start and end addresses
of the keyboard buffer (while making sure that
the RAM you point the buffer to isn't being/going
to be used by anything else!) you can greatly
increase/decrease the buffer size. (For example,the
reference manual for my Heath Zenith 148 computer has
a small program in it which changes the buffer to 4000 bytes.)
1Ah Word Pointer to the first word to be read from the
keyboard buffer- called "Head" by expert keyboard
stuffers like you and I! Note: since the keyboard
buffer is circular in nature, the first word of the
keyboard buffer is not necessarily the first word